//
//  WZAccountSafeController.m
//  ETong
//
//  Created by wanzhao on 15/11/2.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZAccountSafeController.h"
#import "WZMineItem.h"
#import "WZGroupItem.h"
#import "WZMineCell.h"
#import "WZResetPasswordController.h"


@interface WZAccountSafeController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
- (WZGroupItem *)addGroupMineItem;
@property (nonatomic, strong) NSMutableArray *sectionItemArray;



@end

@implementation WZAccountSafeController

- (void)dealloc
{
    NSLog(@"WZAccountSafeController dealloc");
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLORWITH16COLOR(0xeeeeee);
    self.navigationItem.title = @"账户安全";

    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, HARDWARE_SCREEN_HEIGHT - 64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = ClearColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.scrollEnabled = NO;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.view addSubview:self.tableView];
    [self setupSection0];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!IsIOS7) {
        self.navigationController.navigationBar.tintColor = RGBCOLORWITH16COLOR(0x354d6c);
    } else {
        self.navigationController.navigationBar.barTintColor = RGBCOLORWITH16COLOR(0x354d6c);
    }
    
}


- (void)setupSection0
{
    WZMineItem *item = [WZMineItem mineItemWithTitle:@"重置密码" icon:nil];
    item.isHiddenAccessView = NO;
    item.isHiddenBackView = YES;
    item.destVc = [WZResetPasswordController class];
    
    
    WZGroupItem *groupItem = [self addGroupMineItem];
    groupItem.itemArray = @[item];
    
}


- (NSMutableArray *)sectionItemArray
{
    if (_sectionItemArray == nil) {
        _sectionItemArray = [NSMutableArray array];
    }
    return _sectionItemArray;
}

- (WZGroupItem *)addGroupMineItem
{
    WZGroupItem *item = [WZGroupItem groupMineItem];
    [self.sectionItemArray addObject:item];
    return item;
}

- (NSArray *)sectionArray
{
    return self.sectionItemArray;
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.sectionItemArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [self.sectionItemArray[section] itemArray].count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSInteger count = [tableView numberOfRowsInSection:indexPath.section];
    
    WZMineCell *cell = [WZMineCell mineCellWithTableView:tableView];
    WZGroupItem *item = self.sectionItemArray[indexPath.section];
    if (count == 1 || indexPath.row == count - 1) {
        cell.line.hidden = YES;
    } else {
        cell.line.hidden = NO;
    }
    cell.item = item.itemArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return OppositeHeightRate(10);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return OppositeHeightRate(45);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WZGroupItem *groupitem = self.sectionItemArray[indexPath.section];
    WZMineItem *item = groupitem.itemArray[indexPath.row];
    if (item.block != nil) {
        item.block();
    }
    
    if (item.destVc) {
        
        UIViewController *vc = [[item.destVc alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}


@end
